package qj.pooling;

import qj.concurrent.LazyWorker;

import java.io.ByteArrayOutputStream;

/**
 * A byte array output stream pool.
 * <br>
 * Default size is 8192.
 * <br>
 * 8192 is default because at this size, using pool will boost 5x the speed of 
 * acquiring up compare to normal new byte[].
 * Lower than this value, the speed is not improved or can be slower.
 * <br>
 * Created by QuanLA<br>
 * Date: Apr 1, 2006<br>
 * Time: 11:36:26 AM<br>
 */
public class ByteArrayOutputStreamPool extends SimpleObjectPool implements PoolManagable {

    public ByteArrayOutputStreamPool() {
        super(LazyWorker.getInstance());
        setPoolManager(this);
    }

    public Object createNew() {
        return new ByteArrayOutputStream(8192); // 8192 is default because at this size, 
        										// using pool will boost 5x the speed of 
												// acquiring up compare to normal new byte[].
    }

    public boolean bath(Object obj) {
        ((ByteArrayOutputStream)obj).reset();
        return true;
    }

    public boolean prepare(Object obj) {
        return true;
    }

    public void destroy(Object obj) {
    }
}
